#include "comm.hpp"
#include <cstdio>

int main()
{
    int shmid = shared_mem().shmid_get();
    char* shmAddress = (char*)shmat(shmid, nullptr, 0);

    int fd = open(FIFONAME, O_RDONLY); //会等待对方进程open，否则阻塞
    if(fd < 0) { log(FATAL, "%s:%d:open fifo err", __FILE__, __LINE__); exit(1); }

    while(true)
    {
        char c;
        ssize_t s = read(fd, &c, 1); //阻塞，直到read到对方进程写入管道的写入就绪的信息
        if(s < 0) { log(FATAL, "process b:read err"); exit(1); }
        else if(s == 0) { log(LOG, "process b read exit..."); break; } else {}
        std::cout << "process b get a msg: " << shmAddress << std::endl;
    }
    shmdt(shmAddress); //deattach共享内存
    return 0;
}